#include "wmi_disk.h"

using namespace std;
using namespace log4cxx;
using namespace log4cxx::xml;
using namespace log4cxx::helpers;

WMI_Disk::WMI_Disk(IWbemClassObject* plsObj)
{
	setProperties(plsObj);
    DOMConfigurator::configure("LogConfig.xml");
}

WMI_Disk::~WMI_Disk(void)
{
}

void 
WMI_Disk::setProperties(IWbemClassObject* pclsObj)
{
    VARIANT vtProp;
	HRESULT hr;

	hr = pclsObj->Get(bstr_t(NAME.c_str()), 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {            
        setName(wstring(vtProp.bstrVal));
    }

    hr = pclsObj->Get(bstr_t(CAPTION.c_str()), 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setCaption(wstring(vtProp.bstrVal));
    }

    hr = pclsObj->Get(bstr_t(FILESYSTEM.c_str()), 0, &vtProp, 0, 0);
    if(SUCCEEDED(hr))
    {
        setFileSystem(wstring(vtProp.bstrVal));
    }

    VariantClear(&vtProp);
}

void 
WMI_Disk::print()
{
    wstringstream wout;
    LoggerPtr loggerFileDir(Logger::getLogger("loggerFileDir"));

    wout << NAME <<": \""<< getName(); 
    wout <<  "\" " << FILESYSTEM <<": ";
    wout << getFileSystem();
    
    LOG4CXX_INFO(loggerFileDir,wout.str());

    for(vector<WMI_FileDirectory*>::iterator it = _fileDirectories.begin(); it != _fileDirectories.end(); it++)
    {
        (*it)->print();
    }
}